package com.niiwoo.civet.trade.service.local.creditor;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.niiwoo.civet.trade.dao.entity.CreditorSaleBatch;
import com.niiwoo.civet.trade.dao.entity.CreditorSaleDetail;
import com.niiwoo.civet.trade.dao.mapper.CreditorSaleBatchMapperExt;
import com.niiwoo.civet.trade.dao.mapper.CreditorSaleDetailMapperExt;
import com.niiwoo.civet.trade.dto.request.creditor.CreditorSaleOrderPageRequestDTO;

import lombok.extern.slf4j.Slf4j;

/**
 * 债权订单服务类
 * Created by zhoulinquan on 2018/5/14.
 */
@Slf4j
@Service
public class CreditorSaleOrderService {

    @Autowired
    private CreditorSaleBatchMapperExt creditorSaleBatchMapperExt;
    @Autowired
    private CreditorSaleDetailMapperExt creditorSaleDetailMapperExt;
    
    public List<CreditorSaleBatch> getUserCreditorSaleBatchOrderPage(CreditorSaleOrderPageRequestDTO request) {
    	PageHelper.startPage(request.getPageNumber(), request.getPageSize());
    	return creditorSaleBatchMapperExt.getUserCreditorSaleBatchOrderPage(request);
    }

	public List<CreditorSaleDetail> getUserCreditorSaleDetailOrderPage(CreditorSaleOrderPageRequestDTO request) {
		PageHelper.startPage(request.getPageNumber(), request.getPageSize());
		return creditorSaleDetailMapperExt.getUserCreditorSaleDetailOrderPage(request);
	}
    
    public CreditorSaleBatch getCreditorSaleBatchOrderById(String userId, Long creditorSaleBatchId) {
    	if (creditorSaleBatchId == null) return null;
    	
    	CreditorSaleBatch batch = creditorSaleBatchMapperExt.selectByPrimaryKey(creditorSaleBatchId);
    	return batch;
    }
    
    public List<CreditorSaleDetail> getCreditorSaleDetailOrderByBatchId(String userId, Long creditorSaleBatchId) {
    	if (creditorSaleBatchId == null) return null;
    	
    	return creditorSaleDetailMapperExt.getCreditorSaleDetailOrderByBatchId(userId, creditorSaleBatchId);
    }
    
    public CreditorSaleDetail getCreditorSaleDetailOrder(String saleUserId, Long creditorSaleDetailId) {
    	if (creditorSaleDetailId == null) return null;
    	
    	CreditorSaleDetail detail = creditorSaleDetailMapperExt.selectByPrimaryKeyAndSaleUserId(creditorSaleDetailId, saleUserId);
    	
    	return detail;
    }

	public Integer getTradingCreditorSaleDetailNum(String userId) {
		return creditorSaleDetailMapperExt.getTradingCreditorSaleDetailNum(userId);
	}

}
